package org.struts.Listener;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.jdom2.JDOMException;
import org.struts.action.XMLBean;
import org.struts.util.Struts_Xml;

public class ActionListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("context destoryed");
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		ServletContext context = arg0.getServletContext();
		//获取context-param参数
		String xmlpath = context.getInitParameter("struts");
		String realpath = context.getRealPath("\\");
		System.out.println(realpath+xmlpath);
		try {
			Map<String,XMLBean> map = Struts_Xml.readStrutsXml(realpath+xmlpath);
			
			context.setAttribute("strutsMap", map);
			
		} catch (JDOMException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("context initialezed");
	}

}
